/**
 * Created by xinhuang on 15/6/9.
 */
'use strict';

describe('单元测试: 重大活动实时展示页面 指令', function () {
  beforeEach(function () {
    module('directives.customActivity.realtime');
    module('directives.customActivity');
  });

  var $compile, $rootScope, $document;
  beforeEach(inject(function ($injector) {
    $compile = $injector.get('$compile');
    $rootScope = $injector.get('$rootScope');
    $document = $injector.get('$document');
  }));

  describe('当日业务量 busDayVol', function () {
    var scope, element, isolate;

    it('正常显示数据', function () {
      scope = $rootScope.$new();
      scope.selectedModules = [111, 112, 113, 114];
      element = $compile('<bus-day-vol selected-modules="selectedModules"></bus-day-vol>')(scope);
      scope.$digest();

      isolate = element.isolateScope();
      expect(isolate.businessDayVolume).toBeDefined();

      isolate.businessDayVolume.data = {upay: 111, tmall: 112, scpay: 113, bank: 114};
      scope.$digest();

      expect(element.find('tr').length).toBe(4);
      expect(element.find('td').eq(1).html()).toEqual('111');
      expect(element.find('td').eq(3).html()).toEqual('112');
      expect(element.find('td').eq(5).html()).toEqual('113');
      expect(element.find('td').eq(7).html()).toEqual('114');
    });

    it('模块根据配置正确显示', function () {
      scope = $rootScope.$new();
      scope.selectedModules = [];
      element = $compile('<bus-day-vol selected-modules="selectedModules"></bus-day-vol>')(scope);
      scope.$digest();

      expect(element.find('tr').length).toBe(0);
    });
  });

  describe('分时刻业务量: busTimeVol', function () {
    var scope, element, isolate, options;

    it('图表正确初始化', function () {
      scope = $rootScope.$new();
      scope.selectedModules = [121, 122, 123, 124];

      element = $compile('<bus-time-vol selected-modules="selectedModules"></bus-time-vol>')(scope);
      scope.$digest();

      angular.element(document.body).append(element);

      isolate = element.isolateScope();
      expect(isolate.businessTimeVolume).toBeDefined();
      isolate.businessTimeVolume.data = {
        upay: {trancAmount: 122222, volumeOfBus: 122222, volumeTime: '08:00:00'},
        tmall: {trancAmount: 122222, volumeOfBus: 122222, volumeTime: '08:00:00'},
        scpay: {trancAmount: 122222, volumeOfBus: 122222, volumeTime: '08:00:00'},
        bank: {trancAmount: 122222, volumeOfBus: 122222, volumeTime: '08:00:00'}
      };
      isolate.$digest();

      options = isolate.charts.instance.upay.getOption();

      expect(options.xAxis[0].data.length).toBe(24);
      expect(options.xAxis[0].data[23]).toEqual('08:00:00');
      expect(options.series[0].data.length).toBe(24);
      expect(options.series[0].data[23]).toBe(122222);
      expect(options.series[1].data.length).toBe(24);
      expect(options.series[1].data[23]).toBe(122222);
    });

    it('可以添加数据', function () {
      isolate = element.isolateScope();
      isolate.businessTimeVolume.data = {
        upay: {trancAmount: 1222, volumeOfBus: 1222, volumeTime: '08:00:05'},
        tmall: {trancAmount: 1222, volumeOfBus: 1222, volumeTime: '08:00:05'},
        scpay: {trancAmount: 1222, volumeOfBus: 1222, volumeTime: '08:00:05'},
        bank: {trancAmount: 1222, volumeOfBus: 1222, volumeTime: '08:00:05'}
      };
      isolate.$digest();

      options = isolate.charts.instance.upay.getOption();

      expect(options.xAxis[0].data[22]).toEqual('08:00:00');
      expect(options.xAxis[0].data[23]).toEqual('08:00:05');
      expect(options.series[0].data[23]).toBe(1222);
      expect(options.series[1].data[23]).toBe(1222);
    });

    it('模块根据配置正确显示', function () {
      angular.element(document.body).html('');

      scope = $rootScope.$new();
      scope.selectedModules = [121];

      element = $compile('<bus-time-vol selected-modules="selectedModules"></bus-time-vol>')(scope);
      scope.$digest();

      isolate = element.isolateScope();

      expect(isolate.panels.length).toBe(1);
    });
  });

  describe('活动期累计业务量 busTotalVol', function () {
    var element, scope, isolate;

    it('正常显示数据', function () {
      scope = $rootScope.$new();
      scope.selectedModules = [131, 132, 133, 134];
      element = $compile('<bus-total-vol selected-modules="selectedModules"></bus-total-vol>')(scope);
      scope.$digest();

      isolate = element.isolateScope();
      expect(isolate.businessTotalVolume).toBeDefined();

      isolate.businessTotalVolume.data = {upay: 111, tmall: 112, scpay: 113, bank: 114};
      scope.$digest();

      expect(element.find('tr').length).toBe(4);
      expect(element.find('td').eq(1).html()).toEqual('111');
      expect(element.find('td').eq(3).html()).toEqual('112');
      expect(element.find('td').eq(5).html()).toEqual('113');
      expect(element.find('td').eq(7).html()).toEqual('114');
    });

    it('模块根据配置正确显示', function () {
      scope = $rootScope.$new();
      scope.selectedModules = [];
      element = $compile('<bus-total-vol selected-modules="selectedModules"></bus-total-vol>')(scope);
      scope.$digest();

      expect(element.find('tr').length).toBe(0);
    });
  });

  describe('用户充值偏好 userRechargePrefer', function () {
    var element, scope, options, isolate;

    it('正常显示数据', function () {
      scope = $rootScope.$new();
      scope.selectedModules = [151, 152, 153, 154];
      element = $compile('<user-recharge-prefer selected-modules="selectedModules"></user-recharge-prefer>')(scope);
      scope.$digest();

      angular.element(document.body).append(element);

      isolate = element.isolateScope();
      expect(isolate.userRechargePrefer).toBeDefined();

      isolate.userRechargePrefer.data = {
        upay: {rechargeAmount: ['(0,5)'], volumeOfTrans: [11], flag: ['1']},
        tmall: {rechargeAmount: ['(0,5)'], volumeOfTrans: [11], flag: ['1']},
        scpay: {rechargeAmount: ['(0,5)'], volumeOfTrans: [11], flag: ['1']},
        bank: {rechargeAmount: ['(0,5)'], volumeOfTrans: [11], flag: ['1']}
      };
      isolate.$digest();

      options = isolate.charts.instance.upay.getOption();

      expect(options.yAxis[0].data).toEqual(['(0,5)']);
      expect(options.series[0].data).toEqual([11]);
    });

    it('可以刷新数据', function () {
      isolate.userRechargePrefer.data = {
        upay: {rechargeAmount: ['(0,5)'], volumeOfTrans: [111], flag: ['1']},
        tmall: {rechargeAmount: ['(0,5)'], volumeOfTrans: [111], flag: ['1']},
        scpay: {rechargeAmount: ['(0,5)'], volumeOfTrans: [111], flag: ['1']},
        bank: {rechargeAmount: ['(0,5)'], volumeOfTrans: [111], flag: ['1']}
      };
      isolate.$digest();

      options = isolate.charts.instance.upay.getOption();

      expect(options.series[0].data).toEqual([111]);
    });

    it('模块根据配置正确显示', function () {
      angular.element(document.body).html('');
      scope = $rootScope.$new();
      scope.selectedModules = [151];

      element = $compile('<user-recharge-prefer selected-modules="selectedModules"></user-recharge-prefer>')(scope);
      scope.$digest();

      isolate = element.isolateScope();

      expect(isolate.panels.length).toBe(1);
    });
  });

  describe('分省业务量: busProVol 指令', function () {
    var element, scope, options, isolate;

    it('正常显示数据', function () {
      scope = $rootScope.$new();

      element = $compile('<bus-pro-vol></bus-pro-vol>')(scope);
      scope.$digest();

      angular.element(document.body).append(element);

      isolate = element.isolateScope();

      expect(isolate.businessProvinceVolume).toBeDefined();

      isolate.businessProvinceVolume.data = [
        {provinceName: '广东', volume: 99.0, volState: 0},
        {provinceName: '江西', volume: 98.0, volState: 0},
        {provinceName: '湖南', volume: 97.0, volState: 0},
        {provinceName: '浙江', volume: 96.0, volState: 1},
        {provinceName: '上海', volume: 95.0, volState: 1},
        {provinceName: '北京', volume: 94.0, volState: 1}
      ];
      isolate.$digest();

      expect(isolate.range.max[0].provinceName).toEqual('广东');
      expect(isolate.range.max[1].provinceName).toEqual('江西');
      expect(isolate.range.max[2].provinceName).toEqual('湖南');
      expect(isolate.range.min[0].provinceName).toEqual('北京');
      expect(isolate.range.min[1].provinceName).toEqual('上海');
      expect(isolate.range.min[2].provinceName).toEqual('浙江');


      options = isolate.charts.instance['busProVol'].getOption();

      expect(options.series[1].data.length).toBe(3);
      expect(options.series[1].data[0]).toEqual({name: '广东', value: 99.0});
      expect(options.series[2].data.length).toBe(3);
      expect(options.series[2].data[0]).toEqual({name: '浙江', value: 96.0});
    });

    it('可以刷新数据', function () {
      isolate.businessProvinceVolume.data = [
        {provinceName: '广东', volume: 98.0, volState: 0},
        {provinceName: '江西', volume: 97.0, volState: 0},
        {provinceName: '湖南', volume: 96.0, volState: 0},
        {provinceName: '浙江', volume: 95.0, volState: 1},
        {provinceName: '上海', volume: 94.0, volState: 1},
        {provinceName: '北京', volume: 93.0, volState: 1}
      ];
      isolate.$digest();

      expect(isolate.range.max[0].provinceName).toEqual('广东');
      expect(isolate.range.min[0].provinceName).toEqual('北京');

      options = isolate.charts.instance['busProVol'].getOption();

      expect(options.series[1].data.length).toBe(3);
      expect(options.series[1].data[0]).toEqual({name: '广东', value: 98.0});
      expect(options.series[2].data.length).toBe(3);
      expect(options.series[2].data[0]).toEqual({name: '浙江', value: 95.0});
    });

    it('若活动参与省不足6个, 最高最低显示正确', function () {
      isolate.businessProvinceVolume.data = [
        {provinceName: '广东', volume: 98.0, volState: 0},
        {provinceName: '江西', volume: 97.0, volState: 0},
        {provinceName: '湖南', volume: 96.0, volState: 0},
        {provinceName: '浙江', volume: 95.0, volState: 1},
        {provinceName: '上海', volume: 94.0, volState: 1}
      ];
      isolate.$digest();

      expect(isolate.range.max.length).toBe(3);
      expect(isolate.range.min.length).toBe(2);

      expect(isolate.range.max[0].provinceName).toEqual('广东');
      expect(isolate.range.min[0].provinceName).toEqual('上海');
    });
  });

  describe('分省成功率: provinceSuccessrate 指令', function () {
    var element, scope, options, isolate;

    it('正常显示数据', function () {
      scope = $rootScope.$new();

      element = $compile('<province-successrate></province-successrate>')(scope);
      scope.$digest();

      angular.element(document.body).append(element);

      isolate = element.isolateScope();

      expect(isolate.provinceSuccessrate).toBeDefined();

      isolate.provinceSuccessrate.data = [
        {provinceName: '广东', volume: 99.0, volState: 0},
        {provinceName: '江西', volume: 98.0, volState: 0},
        {provinceName: '湖南', volume: 97.0, volState: 0},
        {provinceName: '浙江', volume: 96.0, volState: 1},
        {provinceName: '上海', volume: 95.0, volState: 1},
        {provinceName: '北京', volume: 94.0, volState: 1}
      ];
      isolate.$digest();

      expect(isolate.range.max[0].provinceName).toEqual('广东');
      expect(isolate.range.max[1].provinceName).toEqual('江西');
      expect(isolate.range.max[2].provinceName).toEqual('湖南');
      expect(isolate.range.min[0].provinceName).toEqual('北京');
      expect(isolate.range.min[1].provinceName).toEqual('上海');
      expect(isolate.range.min[2].provinceName).toEqual('浙江');


      options = isolate.charts.instance['provinceSuccessrate'].getOption();

      expect(options.series[1].data.length).toBe(3);
      expect(options.series[1].data[0]).toEqual({name: '广东', value: 99.0});
      expect(options.series[2].data.length).toBe(3);
      expect(options.series[2].data[0]).toEqual({name: '浙江', value: 96.0});
    });

    it('可以刷新数据', function () {
      isolate.provinceSuccessrate.data = [
        {provinceName: '广东', volume: 98.0, volState: 0},
        {provinceName: '江西', volume: 97.0, volState: 0},
        {provinceName: '湖南', volume: 96.0, volState: 0},
        {provinceName: '浙江', volume: 95.0, volState: 1},
        {provinceName: '上海', volume: 94.0, volState: 1},
        {provinceName: '北京', volume: 93.0, volState: 1}
      ];
      isolate.$digest();

      expect(isolate.range.max[0].provinceName).toEqual('广东');
      expect(isolate.range.min[0].provinceName).toEqual('北京');

      options = isolate.charts.instance['provinceSuccessrate'].getOption();

      expect(options.series[1].data.length).toBe(3);
      expect(options.series[1].data[0]).toEqual({name: '广东', value: 98.0});
      expect(options.series[2].data.length).toBe(3);
      expect(options.series[2].data[0]).toEqual({name: '浙江', value: 95.0});
    });

    it('若活动参与省不足6个, 最高最低显示正确', function () {
      isolate.provinceSuccessrate.data = [
        {provinceName: '广东', volume: 98.0, volState: 0},
        {provinceName: '江西', volume: 97.0, volState: 0},
        {provinceName: '湖南', volume: 96.0, volState: 0},
        {provinceName: '浙江', volume: 95.0, volState: 1},
        {provinceName: '上海', volume: 94.0, volState: 1}
      ];
      isolate.$digest();

      expect(isolate.range.max.length).toBe(3);
      expect(isolate.range.min.length).toBe(2);

      expect(isolate.range.max[0].provinceName).toEqual('广东');
      expect(isolate.range.min[0].provinceName).toEqual('上海');
    });
  });

  describe('处理耗时: processTime', function () {
    var element, scope, isolate, ele;

    afterAll(function () {
      angular.element(document.body).html('');
    });

    it('正常显示数据', function () {
      scope = $rootScope.$new();
      scope.selectedModules = [411, 412, 413, 414];
      element = $compile('<process-time selected-modules="selectedModules"></process-time>')(scope);
      scope.$digest();

      angular.element(document.body).append(element);

      isolate = element.isolateScope();

      expect(isolate.processTime).toBeDefined();

      isolate.processTime.data = {
        processTime: 2.59,
        tmProcessTime: 2.59,
        cmProcessTime: 2.59,
        bkProcessTime: 2.59
      };

      isolate.$digest();

      ele = angular.element(document.getElementById('processTime'));

      expect(ele.find('div').eq(1).html()).toEqual('2.59');
    });

    it('可以刷新数据', function () {
      isolate.processTime.data = {
        processTime: 3.01,
        tmProcessTime: 3.59,
        cmProcessTime: 3.59,
        bkProcessTime: 2.59
      };
      isolate.$digest();

      ele = angular.element(document.getElementById('processTime'));

      expect(ele.find('div').eq(1).html()).toEqual('3.01');
    });

    it('模块根据配置正确显示', function () {
      angular.element(document.body).html('');

      scope = $rootScope.$new();
      scope.selectedModules = [411];
      element = $compile('<process-time selected-modules="selectedModules"></process-time>')(scope);
      scope.$digest();
      angular.element(document.body).append(element);

      isolate = element.isolateScope();

      isolate.processTime.data = {
        processTime: 2.59,
        tmProcessTime: 2.59,
        cmProcessTime: 2.59,
        bkProcessTime: 2.59
      };

      isolate.$digest();

      ele = angular.element(document.getElementsByClassName('mypiechart purple'));

      expect(ele.length).toBe(1);
    });
  });

  describe('并发量: throughtput', function () {
    var element, scope, isolate, ele;

    afterAll(function () {
      angular.element(document.body).html('');
    });

    it('正常显示数据', function () {
      scope = $rootScope.$new();
      scope.selectedModules = [421, 422, 423, 424];
      element = $compile('<throughput selected-modules="selectedModules"></throughput>')(scope);
      scope.$digest();

      angular.element(document.body).append(element);

      isolate = element.isolateScope();

      expect(isolate.throughput).toBeDefined();

      isolate.throughput.data = {throughput: 2.59, tmThroughput: 2.59, cmThroughput: 2.59, bkThroughput: 2.59};

      isolate.$digest();

      ele = angular.element(document.getElementById('throughput'));

      expect(ele.find('div').eq(1).html()).toEqual('2.59');
    });

    it('可以刷新数据', function () {
      isolate.throughput.data = {throughput: 3.01, tmThroughput: 3.59, cmThroughput: 3.59, bkThroughput: 2.59};
      isolate.$digest();

      ele = angular.element(document.getElementById('throughput'));

      expect(ele.find('div').eq(1).html()).toEqual('3.01');
    });

    it('模块根据配置正确显示', function () {
      angular.element(document.body).html('');

      scope = $rootScope.$new();
      scope.selectedModules = [421];
      element = $compile('<throughput selected-modules="selectedModules"></throughput>')(scope);
      scope.$digest();

      angular.element(document.body).append(element);

      isolate = element.isolateScope();

      isolate.throughput.data = {throughput: 2.59, tmThroughput: 2.59, cmThroughput: 2.59, bkThroughput: 2.59};

      isolate.$digest();

      ele = angular.element(document.getElementsByClassName('mypiechart deepblue'));

      expect(ele.length).toBe(1);
    });
  });

  describe('吞吐量: tps', function () {
    var element, scope, isolate, ele;

    afterAll(function () {
      angular.element(document.body).html('');
    });

    it('正常显示数据', function () {
      scope = $rootScope.$new();
      scope.selectedModules = [431, 432, 433, 434];
      element = $compile('<tps selected-modules="selectedModules"></tps>')(scope);
      scope.$digest();

      angular.element(document.body).append(element);

      isolate = element.isolateScope();

      expect(isolate.TPS).toBeDefined();

      isolate.TPS.data = {tps: 2.59, tmTps: 2.59, cmTps: 2.59, bkTps: 2.59};

      isolate.$digest();

      ele = angular.element(document.getElementById('tps'));

      expect(ele.find('div').eq(1).html()).toEqual('2.59');
    });

    it('可以刷新数据', function () {
      isolate.TPS.data = {tps: 3.01, tmTps: 3.59, cmTps: 3.59, bkTps: 2.59};
      isolate.$digest();

      ele = angular.element(document.getElementById('tps'));

      expect(ele.find('div').eq(1).html()).toEqual('3.01');
    });

    it('模块根据配置正确显示', function () {
      angular.element(document.body).html('');

      scope = $rootScope.$new();
      scope.selectedModules = [431];
      element = $compile('<tps selected-modules="selectedModules"></tps>')(scope);
      scope.$digest();

      angular.element(document.body).append(element);

      isolate = element.isolateScope();

      isolate.TPS.data = {tps: 2.59, tmTps: 2.59, cmTps: 2.59, bkTps: 2.59};

      isolate.$digest();

      ele = angular.element(document.getElementsByClassName('mypiechart blue'));

      expect(ele.length).toBe(1);
    });
  });

  describe('统一支付成功率: upaySuccessrate', function () {
    var element, scope, isolate, ele;

    afterAll(function () {
      angular.element(document.body).html('');
    });

    it('正常显示数据', function () {
      scope = $rootScope.$new();
      scope.selectedModules = [211, 212];
      element = $compile('<upay-successrate selected-modules="selectedModules"></upay-successrate>')(scope);
      scope.$digest();
      angular.element(document.body).append(element);

      isolate = element.isolateScope();
      expect(isolate.upaySuccessrate).toBeDefined();
      isolate.upaySuccessrate.data = {
        businessProcess: {rate: 99.0, rateState: 1},
        systemProcess: {rate: 99.0, rateState: 2}
      };
      isolate.$digest();


      ele = angular.element(document.getElementsByClassName('panels')).find('li');

      expect(isolate.warn.businessProcess.bgColor).toBe('#f44336');
      expect(isolate.warn.businessProcess.fontColor).toBe('#000');
      expect(isolate.warn.systemProcess.bgColor).toBe('#2196f3');
      expect(isolate.warn.systemProcess.fontColor).toBe('#fff');

      expect(ele.find('canvas').length).toBe(2);
    });

    it('可以更新数据', function () {
      isolate.upaySuccessrate.data = {
        businessProcess: {rate: 97.0, rateState: 2},
        systemProcess: {rate: 97.0, rateState: 1}
      };
      isolate.$digest();

      expect(isolate.warn.businessProcess).toEqual({bgColor: '#2196f3', fontColor: '#fff'});
      expect(isolate.warn.systemProcess).toEqual({bgColor: '#f44336', fontColor: '#000'});
      expect(ele.find('canvas').length).toBe(2);

    });

    it('模块根据配置正确显示', function () {
      angular.element(document.body).html('');
      scope = $rootScope.$new();
      scope.selectedModules = [211];
      element = $compile('<upay-successrate selected-modules="selectedModules"></upay-successrate>')(scope);
      scope.$digest();
      angular.element(document.body).append(element);

      isolate = element.isolateScope();

      isolate.upaySuccessrate.data = {
        businessProcess: {rate: 99.0, rateState: 1},
        systemProcess: {rate: 99.0, rateState: 2}
      };
      isolate.$digest();


      ele = angular.element(document.getElementsByClassName('panels')).find('li');

      expect(ele.find('canvas').length).toBe(1);

    });
  });

  describe('省侧业务处理成功率: provinceBusSuccessrate', function () {
    var element, scope, isolate, ele;

    afterAll(function () {
      angular.element(document.body).html('');
    });

    it('正常显示数据', function () {
      scope = $rootScope.$new();
      scope.selectedModules = [221, 222, 223, 224];
      element = $compile('<province-bus-successrate selected-modules="selectedModules"></province-bus-successrate>')(scope);
      scope.$digest();
      angular.element(document.body).append(element);

      isolate = element.isolateScope();
      expect(isolate.provinceBusSuccessrate).toBeDefined();

      isolate.provinceBusSuccessrate.data = {
        total: {rate: 99.0, rateState: 1},
        tmall: {rate: 99.0, rateState: 1},
        scpay: {rate: 99.0, rateState: 2},
        bank: {rate: 99.0, rateState: 2}
      };
      isolate.$digest();


      ele = angular.element(document.getElementsByClassName('panels')).find('li');

      expect(isolate.warn.total).toEqual({bgColor: '#f44336', fontColor: '#000'});
      expect(isolate.warn.scpay).toEqual({bgColor: '#2196f3', fontColor: '#fff'});
      expect(ele.find('canvas').length).toBe(4);
    });

    it('可以更新数据', function () {
      isolate.provinceBusSuccessrate.data = {
        total: {rate: 99.0, rateState: 2},
        tmall: {rate: 99.0, rateState: 2},
        scpay: {rate: 99.0, rateState: 1},
        bank: {rate: 99.0, rateState: 1}
      };
      isolate.$digest();

      expect(isolate.warn.total).toEqual({bgColor: '#2196f3', fontColor: '#fff'});
      expect(isolate.warn.scpay).toEqual({bgColor: '#f44336', fontColor: '#000'});
      expect(ele.find('canvas').length).toBe(4);

    });

    it('模块根据配置正确显示', function () {
      angular.element(document.body).html('');
      scope = $rootScope.$new();
      scope.selectedModules = [221];
      element = $compile('<province-bus-successrate selected-modules="selectedModules"></province-bus-successrate>')(scope);
      scope.$digest();
      angular.element(document.body).append(element);

      isolate = element.isolateScope();

      isolate.provinceBusSuccessrate.data = {
        total: {rate: 99.0, rateState: 1},
        tmall: {rate: 99.0, rateState: 1},
        scpay: {rate: 99.0, rateState: 1},
        bank: {rate: 99.0, rateState: 1}
      };
      isolate.$digest();


      ele = angular.element(document.getElementsByClassName('panels')).find('li');

      expect(ele.find('canvas').length).toBe(1);

    });
  });

  describe('省侧系统处理成功率: provinceSysSuccessrate', function () {
    var element, scope, isolate, ele;

    afterAll(function () {
      angular.element(document.body).html('');
    });

    it('正常显示数据', function () {
      scope = $rootScope.$new();
      scope.selectedModules = [231, 232, 233, 234];
      element = $compile('<province-sys-successrate selected-modules="selectedModules"></province-sys-successrate>')(scope);
      scope.$digest();
      angular.element(document.body).append(element);

      isolate = element.isolateScope();
      expect(isolate.provinceSysSuccessrate).toBeDefined();

      isolate.provinceSysSuccessrate.data = {
        total: {rate: 99.0, rateState: 1},
        tmall: {rate: 99.0, rateState: 1},
        scpay: {rate: 99.0, rateState: 2},
        bank: {rate: 99.0, rateState: 2}
      };
      isolate.$digest();


      ele = angular.element(document.getElementsByClassName('panels')).find('li');

      expect(isolate.warn.total).toEqual({bgColor: '#f44336', fontColor: '#000'});
      expect(isolate.warn.scpay).toEqual({bgColor: '#2196f3', fontColor: '#fff'});
      expect(ele.find('canvas').length).toBe(4);

    });

    it('可以更新数据', function () {
      isolate.provinceSysSuccessrate.data = {
        total: {rate: 99.0, rateState: 2},
        tmall: {rate: 99.0, rateState: 2},
        scpay: {rate: 99.0, rateState: 1},
        bank: {rate: 99.0, rateState: 1}
      };
      isolate.$digest();

      expect(isolate.warn.total).toEqual({bgColor: '#2196f3', fontColor: '#fff'});
      expect(isolate.warn.scpay).toEqual({bgColor: '#f44336', fontColor: '#000'});
      expect(ele.find('canvas').length).toBe(4);

    });

    it('模块根据配置正确显示', function () {
      angular.element(document.body).html('');
      scope = $rootScope.$new();
      scope.selectedModules = [231];
      element = $compile('<province-sys-successrate selected-modules="selectedModules"></province-sys-successrate>')(scope);
      scope.$digest();
      angular.element(document.body).append(element);

      isolate = element.isolateScope();

      isolate.provinceSysSuccessrate.data = {
        total: {rate: 99.0, rateState: 1},
        tmall: {rate: 99.0, rateState: 1},
        scpay: {rate: 99.0, rateState: 1},
        bank: {rate: 99.0, rateState: 1}
      };
      isolate.$digest();


      ele = angular.element(document.getElementsByClassName('panels')).find('li');

      expect(ele.find('canvas').length).toBe(1);
    });
  });

  describe('全业务流程业务处理成功率: allBusSuccessrate', function () {
    var element, scope, isolate, ele;

    afterAll(function () {
      angular.element(document.body).html('');
    });

    it('正常显示数据', function () {
      scope = $rootScope.$new();
      scope.selectedModules = [241, 242, 243, 244];
      element = $compile('<all-bus-successrate selected-modules="selectedModules"></all-bus-successrate>')(scope);
      scope.$digest();
      angular.element(document.body).append(element);

      isolate = element.isolateScope();
      expect(isolate.allBusSuccessrate).toBeDefined();

      isolate.allBusSuccessrate.data = {
        total: {rate: 99.0, rateState: 1},
        tmall: {rate: 99.0, rateState: 1},
        scpay: {rate: 99.0, rateState: 2},
        bank: {rate: 99.0, rateState: 2}
      };
      isolate.$digest();


      ele = angular.element(document.getElementsByClassName('panels')).find('li');

      expect(isolate.warn.total).toEqual({bgColor: '#f44336', fontColor: '#000'});
      expect(isolate.warn.scpay).toEqual({bgColor: '#2196f3', fontColor: '#fff'});
      expect(ele.find('canvas').length).toBe(4);

    });

    it('可以更新数据', function () {
      isolate.allBusSuccessrate.data = {
        total: {rate: 99.0, rateState: 2},
        tmall: {rate: 99.0, rateState: 2},
        scpay: {rate: 99.0, rateState: 1},
        bank: {rate: 99.0, rateState: 1}
      };
      isolate.$digest();

      expect(isolate.warn.total).toEqual({bgColor: '#2196f3', fontColor: '#fff'});
      expect(isolate.warn.scpay).toEqual({bgColor: '#f44336', fontColor: '#000'});
      expect(ele.find('canvas').length).toBe(4);

    });

    it('模块根据配置正确显示', function () {
      angular.element(document.body).html('');
      scope = $rootScope.$new();
      scope.selectedModules = [241];
      element = $compile('<all-bus-successrate selected-modules="selectedModules"></all-bus-successrate>')(scope);
      scope.$digest();
      angular.element(document.body).append(element);

      isolate = element.isolateScope();

      isolate.allBusSuccessrate.data = {
        total: {rate: 99.0, rateState: 1},
        tmall: {rate: 99.0, rateState: 1},
        scpay: {rate: 99.0, rateState: 1},
        bank: {rate: 99.0, rateState: 1}
      };
      isolate.$digest();


      ele = angular.element(document.getElementsByClassName('panels')).find('li');

      expect(ele.find('canvas').length).toBe(1);
    });
  });

  describe('全业务流程系统处理成功率: allSysSuccessrate', function () {
    var element, scope, isolate, ele;

    afterAll(function () {
      angular.element(document.body).html('');
    });

    it('正常显示数据', function () {
      scope = $rootScope.$new();
      scope.selectedModules = [251, 252, 253, 254];
      element = $compile('<all-sys-successrate selected-modules="selectedModules"></all-sys-successrate>')(scope);
      scope.$digest();
      angular.element(document.body).append(element);

      isolate = element.isolateScope();
      expect(isolate.allSysSuccessrate).toBeDefined();

      isolate.allSysSuccessrate.data = {
        total: {rate: 99.0, rateState: 1},
        tmall: {rate: 99.0, rateState: 1},
        scpay: {rate: 99.0, rateState: 2},
        bank: {rate: 99.0, rateState: 2}
      };
      isolate.$digest();


      ele = angular.element(document.getElementsByClassName('panels')).find('li');

      expect(isolate.warn.total).toEqual({bgColor: '#f44336', fontColor: '#000'});
      expect(isolate.warn.scpay).toEqual({bgColor: '#2196f3', fontColor: '#fff'});
      expect(ele.find('canvas').length).toBe(4);

    });

    it('可以更新数据', function () {
      isolate.allSysSuccessrate.data = {
        total: {rate: 99.0, rateState: 2},
        tmall: {rate: 99.0, rateState: 2},
        scpay: {rate: 99.0, rateState: 1},
        bank: {rate: 99.0, rateState: 1}
      };
      isolate.$digest();

      expect(isolate.warn.total).toEqual({bgColor: '#2196f3', fontColor: '#fff'});
      expect(isolate.warn.scpay).toEqual({bgColor: '#f44336', fontColor: '#000'});
      expect(ele.find('canvas').length).toBe(4);

    });

    it('模块根据配置正确显示', function () {
      angular.element(document.body).html('');
      scope = $rootScope.$new();
      scope.selectedModules = [251];
      element = $compile('<all-sys-successrate selected-modules="selectedModules"></all-sys-successrate>')(scope);
      scope.$digest();
      angular.element(document.body).append(element);

      isolate = element.isolateScope();

      isolate.allSysSuccessrate.data = {
        total: {rate: 99.0, rateState: 1},
        tmall: {rate: 99.0, rateState: 1},
        scpay: {rate: 99.0, rateState: 1},
        bank: {rate: 99.0, rateState: 1}
      };
      isolate.$digest();


      ele = angular.element(document.getElementsByClassName('panels')).find('li');

      expect(ele.find('canvas').length).toBe(1);
    });
  });
});